import { http } from '@/utils/http'
import type {
  GoodsCommentVO,
  GoodsCommentTagVO,
  HotComment,
  CommentTag,
  GoodsCommentDto,
} from './comment.d'

/**
 * 获取商品评论分页列表
 * @param current - 当前页码
 * @param size - 每页数量
 * @param goodsId - 商品ID
 * @param sortOrder - 排序方式（可选）
 * @param tagIds - 标签ID列表（可选）
 */
export const getCommentPage = (
  current: number = 1,
  size: number = 10,
  goodsId: number,
  sortOrder?: 'createTime' | 'score',
  ids?: number,
) => {
  return http<PageResult<GoodsCommentVO>>({
    url: '/goods/comment/list',
    method: 'GET',
    query: { current, size, goodsId, sortOrder, tagIds: ids },
  })
}

/**
 * 获取商品评论标签统计
 *
 * @param id - 商品ID
 */
export const getCommentTags = (id: number) => {
  return http<GoodsCommentTagVO>({
    url: '/goods/comment/getTagById',
    method: 'GET',
    query: { id },
  })
}

/**
 * 添加评论
 *
 */
export const addComment = (data: GoodsCommentDto[]) => {
  return http<boolean>({
    url: '/goods/comment/save',
    method: 'POST',
    data,
  })
}

/**
 * 获取商品热门前三评论
 * @param goodsId - 商品ID
 */
export const getTop3Comments = (goodsId: number) => {
  return http<HotComment[]>({
    url: '/goods/comment/top3',
    method: 'GET',
    query: { goodsId },
  })
}

/**
 * 获取评论标签
 */
export const getTagList = () => {
  return http<CommentTag[]>({
    url: '/goods/comment/tags',
    method: 'GET',
  })
}
